/**
 * 上传文件到“百度云-主机”
 */

path = require('path')
nodeSsh = require('node-ssh')
ssh = new nodeSsh()

function closeSsh() {
    console.log("关闭 SSH 连接")
    ssh.dispose()
}

function uploadFile() {
    ssh.connect({
        host: 'xx.xx.xx.xx',
        username: 'root',
        privateKey: 'C:/Users/Administrator/.ssh/id_rsa_ssh'
    }).then(function () {
        var local = `${path.resolve(process.cwd(), './dist-out/index.html').replace(/\\/g, '/')}`
        console.info(`本地文件：${local}`)
        ssh.putFile(local, '/data/projects/simplest-note-web/dist-out/index.html')
            .then(function () {
                console.log("上传成功")
                closeSsh()
            }, function (error) {
                console.log("上传出错")
                console.log(error)
                closeSsh()
            })
    })
}

console.info(`up 开始 【${new Date().toLocaleTimeString()}】`)

uploadFile()

console.info(`up 结束 【${new Date().toLocaleTimeString()}】`)